package com.cheng.example.atguigu.design_pattern.principle.inversion.improve;

/*
 * @author 程帅
 * @createTime: 2020/10/17 20:06
 * @Created: with IntelliJ IDEA.
 */
public class DependecyInversion {

    public static void main(String[] args) {
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeiXin());
    }
}

//定义接口
interface IReceiver {
    String getInfo();
}

class Email implements IReceiver {
    public String getInfo() {
        return "电子邮件信息：hello,world";
    }
}

// 增加微信
class WeiXin implements IReceiver {
    public String getInfo() {
        return "微信信息：hello,ok";
    }
}

// 方式2
class Person {
    public void receive(IReceiver iReceiver) {
        System.out.println(iReceiver.getInfo());
    }
}
